/// <reference types="vitest" />
import { resolve } from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
const pathResolve = (dir: string): any => {
	return resolve(__dirname, '.', dir);
};
// "build": "npm run build-only  && vue-tsc --emitDeclarationOnly && npm run publish ",

const alias: Record<string, string> = {
	'/@': pathResolve('./src/example/'),
	'/@node_modules/': pathResolve('./node_modules'),
};
// https://vitejs.dev/config/
export default defineConfig({
	plugins: [vue()],
	resolve: { alias },
	build: {
		lib: {
			entry: resolve(__dirname, 'src/packages/index.ts'),
			name: 'SdptSoft',	
			
			fileName: (format) => `sdptsoft.${format}.js`
		},
		rollupOptions: {
			// 确保外部化处理那些你不想打包进库的依赖
			external: ["vue", 'vue-router', 'vuex', 'vant', 'element-plus', "@wangeditor/core", "@wangeditor/editor", "@wangeditor/editor-for-vue"],
			output: {
				// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量	
				exports:'named',		
				globals: {
					vue: "Vue"
				},
			},
		}, // rollup打包配置
	},
	test: {
		environment: 'happy-dom'
	  },
	server: {
		port: 3009,
		open: true,
		hmr: {
			overlay: false
		},
		proxy: {		
			'/q_api': {
				target: 'http://localhost:3003', // 服务器端接口地址,
				ws: false, //如果要代理 websockets，配置这个参数
				changeOrigin: true, //是否跨域
				rewrite: (path) => path.replace('^/q_api', '/q_api'),

			},
		},
	},
})
